<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <link rel="stylesheet" href="../../static/assets/css/zpui.css" />
    <link rel="stylesheet" href="../../static/assets/css/all.css" />
    <script src="../../static/assets/js/page.js"></script>
    
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

    <title> 百问百答 </title>
    <style>
    
    .yhj_title {
    width: 100%;
    display: flex;
    }
    
    .cell_ft {
    padding: 0.3rem;
    height: 100%;
    background-image: url(../../static/mobile/default/images/rightIcon.png);
    background-size: 0.133333rem 0.16rem;
    background-position: center;
    background-repeat: no-repeat;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    text-align: right;
}

.weui-cell {
    padding-top: 0.1rem;
    padding-bottom: 0.1rem;
}
.affirm {
    width: 40px;
    height: 30px;
    float: right;
    position: relative;
    margin-top: -30px;
}

.bottom{
   -moz-transform:rotate(90deg); 
 -webkit-transform:rotate(90deg);
transform:rotate(90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2); 
}


</style>
</head>

<body>
    <div class="page">
        <div class="page-hd">
            <div class="header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">百问百答</div>
                <div class="header-right">
                    <a href="#"></a>
                </div>
            </div>
        </div>

        <div class="page-bd">
            <!-- 页面内容-->
            <div class="member_top" style="background-image:none;    padding-bottom: 0px;">
            <div class="search-bar" >

                    <form action="#">
                    <input type="text" placeholder="请输入问题" id="seek" style="height: 0.573333rem;
  line-height: 0.573333rem;
  border-radius: 0.286667rem;border: solid 1px #eeeeee;">
                    </form>
                <div class="affirm" onclick="seek()" style="height: 0.573333rem;
  line-height: 0.573333rem; margin-top: -45px;"></div>  

            </div>

        </div>
            <!-- 容器 -->
            <div class="weui-tab">

                <div class="weui-tab__bd">
                    <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active shop-list">
                        <script type="text/html" id="orderTpl">
                            {{each data as item index}}
                            <div class="weui-cells">
                                <div class="weui-cell">
                                    <div class="weui-cell__bd">
                                        <div class="fs28  yhj_title"  data='hidden'  onclick='yhj_title($(this))'>
                                        <div style='flex: 1;line-height: .4rem;padding:.1rem 0'>{{item.question}}</div>
                                        <div class="cell_ft"></div>
                                        </div>
                                        <div class="fs24 text-muted mt30" style='display:none'>{{item.answer}} 
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {{/each}}
                        </script>
                    </div>

                </div>
            </div>

        </div>

    </div>

    <script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
    <script src="../../static/assets/js/jquery-weui.min.js"></script>
    <script src="../../static/js/jquery/jquery.cookie.js"></script>
    <script src="../../static/assets/js/lib/fastclick.js"></script>
    <script src="../../static/tpl/js/art-template.js"></script>
    <script src="../../static/mobile/default/js/page.js"></script>
      <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });
    </script>
    <script>
    
  
        //添加到购物车
        function addToCart(obj, goods_id, type, number, delive_id, prom_type = 0, prom_id = 0) {
            var arr = new Object;
            arr.goods_id = goods_id;
            // arr.specifications = obj.data('sku');
            // if (typeof(arr.specifications) != 'undefined') {
            //     arr.sku_id = sub_goods[arr.specifications].sku_id;
            // }
            if (number == 0) {
                $.alert('现金卷数量不足');
                return;
            }
            arr.type = type;
            arr.number = number;
            arr.prom_type = prom_type;
            arr.prom_id = prom_id;
            arr.delive_id = delive_id;

            //var res = jq_ajax("/shop/api.flow/addcart.html", arr);
            $.post("/shop/api.flow/addcart.html", arr, function(res) {
                if (res.code == 1) {
                    if (arr.type == 'onbuy') {
                        window.location = '/shop/flow/checkout/rec_id/'+res.rec_id+'/delive_id/'+res.delive_id+'.html';
                        return false;
                    }
                    //$('.cartNum').html(res.cartInfo.num);
                }
                if (res.code == 2) {
                    if (res.errmsg) $.alert(res.errmsg);
                    return false;
                }
                if (arr.type == 'onbuy') {
                    // if (res.errmsg) _alert(res.errmsg, function() {
                    //     // window.location.href = '/member/passport/login.html';
                    // });
                    return;
                }
                if (res.errmsg) $.alert(res.errmsg);
            })

        }


        var nowPage = [],
            getAgain = [],
            isLoadend = [];
        var _type = "shop-list";
        var type = 1;
        var tplid = 'orderTpl';
      share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
	    
	    
	    
        $(function() {

            $('a.weui-navbar__item').click(function() {
                if ($(this).attr('data-type') != type) {
                    type = $(this).attr('data-type');
                    isLoadend[_type] = false;
                    getAgain[_type] = false;
                    nowPage[_type] = 1;
                    get = false;
                    $('.' + _type + '').html('');
                    getList();
                }
            })
            getList();
            var get = false;
            // 当用户滚动到页面底部的时候加载更多内容。
            $('.shop-list').infinite(10);
            $('.shop-list').infinite().on("infinite", function() {
                if (get) return;
                getList();
            })
            
             

            //请求列表数据
            

        })
        function seek(){
                  
                 nowPage[_type] =1
                 getList('',true)
                 
                 
             }
             
                                      function yhj_title(params){
                                          
                                          console.log('test',params)
                                if(params.attr('data') == 'hidden'){
                                    params.next().show()
                                    params.find('.cell_ft').addClass('bottom')
                                    params.attr('data','show')
                                }else{
                                    params.next().hide()
                                    params.attr('data','hidden')
                                    params.find('.cell_ft').removeClass('bottom')
                                }
                                
                                
                               
        
    }
        
        function getList(isagain,isornot) {
                page = nowPage[_type];
                if (typeof(page) == 'undefined') page = 1;
                if(isornot){isLoadend[_type] = false}
                if (isLoadend[_type] == true) return false;
                if (isagain == true) {
                    if (getAgain[_type] == false) return false;
                    getAgain[_type] = false;
                } else {
                    $('.' + _type + '').append('<div id="jz" style="margin-bottom:20px;" class="fs24 text-muted mt30 tc">内容加载中~</div>');
                }
                isLoadend[_type] = true;
                $.ajax({
                    url: 'https://mp.jianguoes.com/api/mp/pageIssue', // 跳转到 action
                    data: {
                         'page':page,
                        'size':10,
                        'question':$('#seek').val()
                    },
                    type: 'get',
                    headers:{'token': $.cookie('code')},
                            dataType: 'json',
                    success: function(res) {
                        isLoadend[_type] = false;
                        if (res.errno != 0) {
                            $.alert(res.errmsg);
                            getAgain[_type] = true;
                            $('.' + _type + '').find('#jz').html('加载失败，点击重新加载.');
                            return false;
                        }
                       
                        $('#jz').remove();
                        if(isornot == true){
                            $('.' + _type + '').html('')
                        }
                        
                        if (res.data.data.length > 0) {
                             nowPage[_type] = page + 1;
                            $('.' + _type + '').append(template('orderTpl', res.data));
                             $('.text-muted').each(function(i){
                                    var text =$('.text-muted').eq(i).text()
                                    $('.text-muted').eq(i).html(text)
                                })
                            

                        } else {
                            $('.' + _type + '').html('<div class="empeyOrder" style="width: 100%;text-align: center;">\
                                <img style = "width: 100%;" src = "/static/mobile/default/images/emptyData.png" alt = "">\
                                <span class="fs24 text-muted tc mt30">暂无记录</span>\
                            </div>');
                        }

                        $('.weui-bar__item--on span').text('('+res.data.data.length+')')
                        if (res.data.totalPages == page) {
                            $('.' + _type + '').append('<div id="jz" style="margin-bottom:20px;" class="fs24 text-muted mt30 tc">---我也有底线的---</div>');
                            isLoadend[_type] = true;
                            get = true;
                        }
                    },
                    error: function() {
                        isLoadend[_type] = false;
                        getAgain[_type] = true;
                        $('.' + _type + '').find('#jz').html('加载失败，点击重新加载.');
                    }
                });
            }
    </script>
</body>


</html>